$(function () {
    //全局定义页数与总条数
    var markid = getUrlString('markid');
    var key = getUrlString('key');
    // var markid = '3b70887e5d841ff8ab7388ea5f41a5af';
    var page = -1,totalSize = 0,sort= 0;


    var mRefresh = new MiniRefresh({
        container: '#usedmRefresh', //这里是插件的容器ID
        isLockX:false,
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#usedList').empty();
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                getDate(page)
            }
        }
    });

    /*联网加载列表数据*/
    function getDate(page) {
        //延时一秒,模拟联网
        var params = {
            'key':key,
            'markid':markid,
            'page': page,
        };
        getData('get', '/niu/apiv3/ershou_ershoulist.php', params, function (data) {
            console.log(data);
            if(data.resultcode === '0' ){
                var append = '';
                $(data.data).each(function () {
                    var picUrls =  this.pics;
                    var picUrlsArr = picUrls.split(';');
                    append += '<li>' +
                        '           <input type="hidden" class="id" value="'+this.id+'"> '+
                        '                    <div class="pic">' +
                        '                        <img src="'+picUrlsArr[0]+'" alt="">' +
                        '                    </div>' +
                        '                    <div class="name">'+this.name+'</div>' +
                        '                    <div class="info">' +
                        '                        <span class="infoNum">￥'+this.price+'</span>' +
                        '' +
                        '                        <span class="like">' +
                        '                            <img src="../../res/img/pullEgg/dz1.png" alt="">' +
                        '                            <span class="likeNum">'+this.zancount+'</span>' +
                        '                        </span>' +
                        '                    </div>' +
                        '                    <div class="price">' +
                        '                        <img src="'+this.faceurl+'" alt="">' +
                        '                        <span class="nickName">'+this.nick+'</span>' +
                        '                    </div>' +
                        '                </li>'
                });
                $('#usedList').append(append);
                if (page === 0){
                    mRefresh.scrollTo('5','30');
                }

                totalSize = totalSize + 10;
                if (totalSize > data.datacount)
                    mRefresh.endUpLoading(true);
                else{
                    mRefresh.endUpLoading(false);
                }


                //二手详情
                $('#usedList li').click(function () {
                    var id = $(this).find('.id').val();
                    window.location.href = 'dancool://ershou='+id;
                });
            }else {
                laymsg(data.msg)
            }

        });
    }
    //发表二手商品
    $('#releaseUsed img').click(function () {
        window.location.href = 'dancool://postershou=';
    });




});